<template>
	<!-- 下达修改 -->
	<view class="p-10">
		<view class="card">
			<my-forms ref="valiForm" :model="valiFormData" :label-position="'top'" :formItem="formData" label-width="180rpx"></my-forms>
			<u-button class="m-t-20" type="primary" shape="circle" text="提交" @click="submit"></u-button>
		</view>
	</view>
</template>
<script setup>
import { computed, ref, unref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { oneDetailPostpone, editPostpone } from '@/api/hidden-danger.js';

// 表单数据
const formData = computed(() => {
	return [
		{
			itemType: 'radio',
			list: [
				{
					label: '批准'
				},
				{
					label: '驳回'
				}
			],
			label: '审批',
			prop: 'examinState'
		},
		{
			label: '申请人',
			disabled: true,
			prop: 'applyUserName'
		},
		{
			itemType: 'date',
			type: 'date',
			label: '申请限制日期',
			disabled: true,
			prop: 'applyChangeDate'
		},
		{
			type: 'select',
			label: '受理人',
			disabled: true,
			prop: 'examinUserName'
		},
		{
			type: 'select',
			label: '申请次数',
			disabled: true,
			prop: 'applyNum'
		},
		{
			label: '申请原因',
			type: 'textarea',
			disabled: true,
			prop: 'applyMessage'
		},
		{
			itemType: 'radio',
			list: [
				{
					label: '按照申请日期'
				},
				{
					label: '重新指定日期'
				}
			],
			label: '日期',
			prop: 'isDate',
			show: valiFormData.value.examinState == 0
		},
		{
			itemType: 'date',
			type: 'date',
			label: '新的限制日期',
			required: true,
			prop: 'newApplyChangeDate',
			show: valiFormData.value.examinState == 0 && valiFormData.value.isDate == 1
		},
		{
			type: 'textarea',
			label: '驳回原因',
			required: true,
			prop: 'remark',
			show: valiFormData.value.examinState == 1
		}
	].filter((i) => i);
});

const valiForm = ref(null);
const valiFormData = ref({
	examinState: 0,
	isDate: 0
});
let ids = ref(''),
	resid = ref('');
// 保存提交
const submit = () => {
	valiForm.value.$refs.refMyForm
		.validate()
		.then(async (res) => {
			const { code } = await editPostpone({
				id: unref(ids),
				checkPlanId: unref(resid),
				...unref(valiFormData)
			});
			if (code == 200) {
				uni.showToast({
					title: `批复成功`,
					success() {
						uni.navigateBack({
							delta: 1
						});
					}
				});
			}
		})
		.catch((err) => {
			console.log('err', err);
		});
};
onLoad(async (e) => {
	const { id, checkPlanId } = e;
	ids.value = id;
	resid.value = checkPlanId;
	const { data } = await oneDetailPostpone({
		checkPlanId
	});
	valiFormData.value = data;
	valiFormData.value.isDate = 0;
});
</script>
<style lang="scss" scoped></style>
